{include file="public:header"}
<!--aside nav-->
{include file="public:left"}

<div class="content-box-content">
  <div class="tab-content default-tab" id="form" style="display: block;">
    <form method="post" action="submitsms.aspx" name="clientForm" id="clientForm">
      <table cellspacing="0" cellpadding="0" width="100%" border="0">
        <tbody>
          <tr class="alt-row">
            <td height="28" style="line-height:28px;" width="13%" align="right">源号码：</td>
            <td valign="top" style="padding-top:8px;">
              <textarea name="mobile" style="border:1px solid #6E9FDE;width:380px; height:85px; margin-bottom:5px;" id="mobile" rows="6" onblur="CountNum();" onchange="CountNum();"></textarea>
            </td>
          </tr>
          <tr>
            <td height="28" style="line-height:28px;" width="13%" align="right" ></td>
            <td valign="top" style="padding-top:8px;">
              <div id="mobiletip" style="color:red;margin-left:7px;line-height:24px;height:24px;margin-top:0;margin-bottom:0;">共计号码：<span id="mobile_list">0</span> 个
            </td>
          </tr>
          <tr class="alt-row">
            <td height="28" style="line-height:28px;" width="13%" align="right"></td>
            <td valign="top" style="padding-top:8px;" colspan="6">
              <div style="margin-top:0;margin-bottom:0;">
                <input name="imptxt" id="imptxt" class="button" style="margin-bottom:3px;" onclick="send();" type="button" value=" TXT导入 ">
                <input name="impexcel" id="impexcel" class="button" style="margin-bottom:3px;margin-left:5px;" onclick="sendexcel()" type="button" value=" EXCEL导入 ">
                <br/>
                <input name="checkmobile" id="checkmobile" class="link_btn" style="margin-top:15px;margin-left:0px;"  type="button" onclick="send_sms()" title="分包" value="号码入库">
                </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
<script>
    function repeat(){
      var textarea = document.getElementById("mobile");
      if(textarea.value == ""){
        return;
      }
    
      var temp = textarea.value.split(/[\n,]/g);
      var temps = [];
      var r = 0;
      for(var i = 0; i<temp.length; i++){
        if(temps.indexOf(temp[i]) == -1){
          temps.push(temp[i]);
          r++;
        }
      }
      textarea.value = temps.join(",");
      $("#mobile_list").text(r);
    }
    function clearErro() {
      var textarea = document.getElementById("mobile");
      var patrn = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘’，。、]/ig; 
      var tem = textarea.value.replace(patrn,",");
      var temp = tem.split(/[\n,]/g);
      
      var temps = [];
      var r = 0;
      for(var i = 0; i<temp.length; i++){
        temp[i] = temp[i].replace(/\s+/g,"");
        
        if(/^1(3|4|5|7|8)\d{9}$/.test(temp[i]) && temps.indexOf(temp[i]) == -1){ 
          temps.push(temp[i]);
          r++;
        } 
      }
      
      textarea.value = temps.join(",");
      $("#mobile_list").text(r);
    }
    function CountNum(){
      repeat();
      clearErro();
    }

    //txt导入
    function send() {
        var url="{:url('Sms/txt_add')}";

        //页面层
        layer.open({
          type: 2,
          title:'上传txt文件',
          skin: 'layui-layer-rim', //加上边框
          area: ['200px', '200px'], //宽高
          content: url
        });
    }
    //sendexcel
    function sendexcel() {
        var url="{:url('Sms/exel_add')}";

        //页面层
        layer.open({
          type: 2,
          title:'上传exel文件',
          skin: 'layui-layer-rim', //加上边框
          area: ['200px', '200px'], //宽高
          content: url
        });
    }

    function send_sms(){
      var formData = new FormData();
      var mobile = $('#mobile').val();

      if(mobile == ""){
        alert('电话为空!');
        return;
      } 


      formData.append('mobile_string',mobile);

      $.ajax({
          url:"{:url('Sms/mobile_lib')}",
          type:'POST',
          data:formData,
          async:false,
          processData:false,
          contentType:false,
          success:function(result) {
              if(result.code == '1'){
                window.location.href=result.url
              }else{
                alert(result.msg);
              }
          }
      });
    }
</script>
</div>
</body>
</html>
